﻿<cfcomponent displayname="Creation" output="false">
    <cfscript>
        this.DOMAINCONTROLLER = '10.100.1.101';
        this.ORG_SCF = '117';
        this.DOLLARS = "2";
        this.USA = "5";
        this.Error = "False";
        this.EmpStatusReason = "";
        this.StepID = "-1";
        this.ErrorMessage = "";
        this.Manual= "0";
        this.PRIMARY_POS = "-1";
        this.PROMOTION = "-1";
        this.BASEPAY = "-1";
        this.COMP_LOCATION_FACTOR = "1.00";
        this.ACTIVE = "-10131";
        this.I9_PENDING = "-10157";
        this.EMP_ADDRESS_TYPE = "17";
        this.REHIRE = "3";
        this.HOMEDIRECTORY = "G:";
        this.MAILSERVER = "SCFMX";
        this.ES_REASON_NEW_HIRE = "5";//ES=EMPLOYMENT
        this.PS_REASON_NEW_HIRE = "53";//PS=PAY 
        this.PP_REASON_NEW_HIRE = "44";//PP=POSITION
        this.ES_REHIRE = "6";//ES=EMPLOYMENT
        this.PS_REHIRE = "54";//PS=PAY
        this.PP_REHIRE = "45";
        this.NewHRPersonIDNo = -1;
        this.ReHirePersonIDNo = -1;
        this.Mirror = "EPARBasic";
        this.SCF = "Southcentral Foundation";
        this.NewUserAccount = "";
        this.NewADGUID = "";
        this.HRSupervisorID = "";
        this.NewRosettaID = "-1";
        this.MailboxCreated = 0;
        this.Rehire = 0;
        this.CheckRehire = -1;
        this.Seasonal = -1;
        this.AnnualSalary = 0;
        this.FullTime = 0;
        this.trace = '';  
    </cfscript>  
    
    
    <cffunction name="init" access="public" output="false" returntype="Creation">
        <cfscript>
            return this;
        </cfscript>
    </cffunction>    
            
    
    <cffunction name="setStepID" access="public" output="false" returntype="any">
        <cfargument name="StepID" type="string" required="true" default="-1" />
        <cftry>
            <cfscript>
                KronosQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.Kronos");
                AccessControlQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.AccessControl");
                JustinsJobProg = CreateObject("component", session.rootDir & ".DatabaseQueries.JustinsJobProg");
                this.StepID = ARGUMENTS.StepID;
                StepAction = EntityLoad ("StepActions", this.StepID);
                this.Employee = EntityLoad("Employee", StepAction[1].getEmployeeID());
                this.Employee = this.Employee[1];//returns an array of one
                this.Container = EntityLoad("ADContainer", this.Employee.getContainerID());
                this.Container = this.Container[1];
                this.NextMailServer = "SCFExch" & RandRange(1, 3);//randomly select a exchange server to load balance.
                this.EmpECInfo = ORMExecuteQuery("FROM Contacts WHERE EmployeeID = " & this.Employee.getEmployeeID() & " AND ContactTypeID = 2");
                this.StepAction = ORMExecuteQuery("FROM StepActions WHERE StepActionsID = " & this.StepID);
                this.StepAction = this.StepAction[1];
                this.Depts = KronosQueries.funcGetDepts();
                this.Department = KronosQueries.funcGetDepts(this.Employee.getDepartmentID());
                this.PositionInfo = KronosQueries.funcGetPositionCodes(this.Employee.getPositionID()); 
                this.AF = KronosQueries.funcGetAF(this.Employee.getFrequencyID()); //tSY_PAY_RATE_FREQUENCY_CODES
                this.Position =  KronosQueries.funcGetPositions(this.Employee.getPositionID());
                this.Dept = KronosQueries.funcGetDepts(this.Employee.getDepartmentID());                
                this.Supervisor = KronosQueries.funcGetCurrentEmployees(this.Employee.getSupervisorID());
                this.CreationOU = "OU=" & #this.Container.getContainer()# & ";";
                this.CheckRehire = KronosQueries.funcCheckRehire(this.Employee.getSSN());
                this.Rehire = KronosQueries.funcCheckRehire(this.Employee.getSSN()).RecordCount == 0 ? False : True;
                this.Exempt = this.Employee.getSalaryHourlyID() == -10192 ? -1 : 0;
                this.Seasonal = this.Employee.getSeasonal() ? -1 : 0;
                this.FullTime = this.Employee.getFullTime() ? -1 : 0;
                this.AnnualSalary = (this.Employee.getPayRate() * this.AF.AnnualizingFactor);
            </cfscript>
        <cfcatch type="any">
            <cfset this.Error = true />
            <cfset this.ErrorMessage = "Message:#CFCATCH.Message# Detail:#CFCATCH.Detail#" />
        </cfcatch>
        </cftry>      
    </cffunction>    

    
    
    <cffunction name="createMailboxADAccount" access="public" output="false" returntype="any">
        <cftry>
            <cfscript>
                Var retObj = { Message = "", Result = "", Status = 'Fail'};
                Var useraccount = "#Left(this.Employee.getFirstName(), 1)#" & "#this.Employee.getLastName()#";
                useraccount = constructUserAccount(this.Employee.getFirstName(), this.Employee.getLastName());
                NewMailbox = 'New-Mailbox -UserPrincipalName ' & useraccount.UserAccount & '@scf.cc -Alias ' & useraccount.UserAccount 
                    & ' -database "#this.NextMailServer#\First Storage Group\Mailbox Database" -Name "#useraccount.Name#"'
                    & ' -OrganizationalUnit ' & this.Container.getContainer() 
                    & ' -password (ConvertTo-SecureString "Password10!" -AsPlainText -Force) ' 
                    & ' -FirstName ' & this.Employee.getFirstName() 
                    & ' -LastName ' & this.Employee.getLastName() 
                    & ' | ft -HideTableHead Name | Out-String -Width 10000';
                ps = usePowerShell(
                    'add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
                    ' & NewMailbox & ''
                );
                ps = usePowerShell(
                    'add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
                    Set-Mailbox #useraccount.UserAccount# -UseDatabaseQuotaDefaults:$False -IssueWarningQuota 240MB -ProhibitSendQuota 250MB -ProhibitSendReceiveQuota 250MB'
                );
                this.MailboxCreated = 1;
                this.NewUserAccount = useraccount.UserAccount;
                this.Employee.setADUserID( useraccount.UserAccount );
                
                sleep(6000);
                scfad = CreateObject("component", "code_lib.SCF_ActiveDirectory");
                NewUserDN = scfad.getUserDNByAccountName(useraccount.UserAccount);
                SupervisorDN = scfad.getUserDNByAccountName(this.Supervisor.UserAccount);
                scfad.replaceAttributesByDN( NewUserDN, 'title=#this.Position.PositionCodeDescription#');
                scfad.replaceAttributesByDN( NewUserDN, 'description=#this.Position.PositionCodeDescription# (#trim(this.Position.PositionCode)#)');
                scfad.replaceAttributesByDN( NewUserDN, 'physicalDeliveryOfficeName=#this.Dept.OrganizationDescription#');
                scfad.replaceAttributesByDN( NewUserDN, 'homeDirectory=#this.Container.getHomeDir()#\#useraccount.UserAccount#');
                scfad.replaceAttributesByDN( NewUserDN, 'manager=#SupervisorDN#');
                scfad.replaceAttributesByDN( NewUserDN, 'homeDrive=#this.HOMEDIRECTORY#');
                scfad.replaceAttributesByDN( NewUserDN, 'department=#this.Dept.OrganizationDescription#');
                
                //set password to Password10!
                usePowerShell('
                    $user = [ADSI]"LDAP://#NewUserDN#"
                    $user.Invoke("setpassword", "Password10!")
                '); 
                
                //contractor expiration date.
                if( this.Employee.getNonSCFTypeID NEQ ""){
                    PowerShellDate = usePowerShell("(Get-Date #DateFormat(this.Employee.getActStartDate(),'mm/dd/yyyy')#).ToFileTime()");
                    scfad.replaceAttributesByDN( NewUserDN, 'accountExpires=#PowerShellDate#');
                }
                
                EntitySave(this.Employee);
                retObj = { Message = "<strong>Success</strong>", 
                    result = "#useraccount.UserAccount#@southcentralfoundation.com was created on #DateFormat(now(), 'mm/dd/yyyy')#", 
                    Status = 'Created'
                };
                return retObj;
            </cfscript>
        <cfcatch type="any">
            <cfscript>
                usePowerShell(
                    'add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
                     remove-mailbox -Identity ' &  this.Employee.getADUserID() & ' -Confirm: $false'
                );
                this.Employee.setADUserID("");
                EntitySave(this.Employee);           
                retObj = { Message = "<strong>Error</strong> - #CFCatch.Detail#", Result = "Error Creating mailbox and AD account.  Error detail:<br />#CFCatch.Detail# #CFcatch.message#", Status = 'Fail'};
                creationErrorLog(this.StepID, '#replace(retObj.Result,"\'","'","all")#');
                AlertEmail("Error Creating mailbox and AD account.", retObj.Result);
                return retObj;
            </cfscript>
        </cfcatch>
        </cftry>
    </cffunction>
    
    
    <cffunction name="createHRAccount" access="public" output="false" returntype="any">
        <cftry>
            <cfscript>
                Var retObj = { Status = "Fail", Message = "", Result = "" };
                if( this.Rehire ){
                    ce = CreateEmployeeRehire();
                    upp = UpdatePrimaryPhones();
                    ceap = CreateEmployeeAddressesPhones();
                    ceec = CreateEmployeeEmergencyContact();
                    retObj.Status = 'Created';
                    retObj.Message = '<strong>Success</strong>';
                    return retObj;
                }else{
                    ce = CreateEmployee();
                    ceap = CreateEmployeeAddressesPhones();
                    ceec = CreateEmployeeEmergencyContact();
                    retObj.Status = 'Created';
                    retObj.Message = '<strong>Success</strong>';
                    return retObj;
                }               
            </cfscript>
        <cfcatch type="any">
            <cfscript>
                usePowerShell(
                    'add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
                     remove-mailbox -Identity ' &  this.Employee.getADUserID() & ' -Confirm: $false'
                );
                this.Employee.setADUserID("");
                EntitySave(this.Employee);
                retObj = { Message = "<strong>Error</strong> - #CFCatch.Message#", Result = "Error Creating HR account.  Error detail:<br />" & CFCatch.Detail & " " & this.trace, Status = 'Fail' };
                creationErrorLog(this.StepID, '#replace(retObj.Result,"\'","'","all")#');
                AlertEmail("Error Creating HR account.", retObj.Result & " " & this.trace);
                return retObj;
            </cfscript>
        </cfcatch>
        </cftry>
    </cffunction>
    
    
    <cffunction name="createRosettaAccount" access="public" output="false" returntype="any">
        <cftry>
            <cfscript>
                Var retObj = { Status = "Fail", Message = "", Result = "" };
                NewRosetta = entityNew("RosettaStone");
                NewRosetta.setUserAccount(this.Employee.getADUserID());
                NewRosetta.setEPAR_ID(this.Employee.getEmployeeID());
                NewRosetta.setHRProd_PersonIDNo(this.Employee.getHRPersonIDNo());
                entitySave(NewRosetta, true);
                this.Employee.setRosettaID(NewRosetta.getRosettaID());
                EntitySave(this.Employee);
                retObj = { Status = "Created", Message = "<strong>Success</strong>", Result = "" };
            </cfscript>
             
            <cfmail bcc="#Session.ITS_EMAIL#" to="#this.Supervisor.UserAccount#@scf.cc" from="""HR Dept - EPAR System"" <noreply@scf.cc>"  type="html" subject="Employee Hire Update">
                <p>The employee, <strong>#this.Employee.getFirstName()# #this.Employee.getLastName()#</strong>, is now in the SCF system.  
                    Here is some information regarding their status and user account.<BR />
                </p>
                <table>
                    <tr>
                        <td width='5'>&nbsp;</td>
                        <td>Network User Account:</td>
                        <td width=25>&nbsp;</td>
                        <td>#this.Employee.getADUserID()#</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>Password (required to change @ first login):</td>
                        <td>&nbsp;</td>
                        <td>Password10! (case sensitive)</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>Date of Hire:</td>
                        <td>&nbsp;</td>
                        <td>#dateFormat(this.Employee.getActStartDate(), 'mm/dd/yyyy')#</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>Desk Phone:<BR />(as it will appear in the Address Book)</td>
                        <td>&nbsp;</td>
                        <td>#this.Employee.getDeskPhone()#</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>Job Title:</td>
                        <td>&nbsp;</td>
                        <td>#this.PositionInfo.PositionCodeDescription#</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>Home Directory:</td>
                        <td>&nbsp;</td>
                        <td>#this.Container.getHomeDir()#\#this.Employee.getADUserID()#</td>
                    </tr>
                </table>                        
            </cfmail>
            <cfscript>
                return retObj;
            </cfscript>   
        <cfcatch type="any">
            <cfscript>                
                retObj = { Message = "<strong>Error</strong> - #CFCatch.Detail#", Result = "Error Creating Rosetta account.  Error detail:<br />" & CFCatch.Detail, Status = 'Fail' };
                creationErrorLog(this.StepID, '#replace(retObj.Result,"\'","'","all")#');
                AlertEmail("Error Creating Rosetta account.", retObj.Result);           
                return retObj;
            </cfscript>
        </cfcatch>
        </cftry>
    </cffunction>
    
    
    <cffunction name="createNonSCFMasterAccount" access="public" output="false" returntype="any">
        <cftry>
            <cfscript>
                Var retObj = { Status = "Fail", Message = "", Result = "" };
                NonSCFMaster = EntityNew("NonSCFMaster");
                NonSCFMaster.setFirstName( this.Employee.getFirstName() );
                NonSCFMaster.setLastName( this.Employee.getLastName() );
                NonSCFMaster.setMiddleName( this.Employee.getMiddleName() );
                NonSCFMaster.setPreferredName( this.Employee.getPreferredName() );
                NonSCFMaster.setDisplayName( this.Employee.getFullName() );
                NonSCFMaster.setSSN( this.Employee.getSSN() );
                NonSCFMaster.setEmail( this.Employee.getADUserID() & "@scf.cc" );
                NonSCFMaster.setWorkPhone( this.Employee.getWorkPhone() );
                NonSCFMaster.setCompany( this.Employee.getCompanyName() );
                NonSCFMaster.setDepartment( this.Department.OrganizationDescription );
                NonSCFMaster.setSupervisor( this.Supervisor.FirstName & ' ' & this.Supervisor.LastName & " (" & this.Supervisor.UserAccount & ")" );
                NonSCFMaster.setNonSCFTypeID( Val(this.Employee.getNonSCFTypeID()) );
                EntitySave(NonSCFMaster, true);
                
                NewRosetta = entityNew("RosettaStone");
                NewRosetta.setUserAccount(this.Employee.getADUserID());
                NewRosetta.setEPAR_ID(this.Employee.getEmployeeID());
                NewRosetta.setNonSCFMasterID( NonSCFMaster.getNonSCFMasterID() );
                entitySave(NewRosetta, true);
                this.Employee.setRosettaID(NewRosetta.getRosettaID());
                EntitySave(this.Employee);
                retObj = { Status = "Created", Message = "<strong>Success</strong>", Result = "" };
            </cfscript>
            <cfmail bcc="#Session.ITS_EMAIL#" to="#this.Supervisor.UserAccount#@scf.cc" from="""HR Dept - EPAR System"" <noreply@scf.cc>"  type="html" subject="Employee Hire Update">
            <p>The employee, <strong>#this.Employee.getFirstName()# #this.Employee.getLastName()#</strong>, is now in the SCF system.  
                Here is some information regarding their status and user account.<BR />
            </p>
            
            <table>
                    <tr>
                        <td width='5'>&nbsp;</td>
                        <td>Network User Account:</td>
                        <td width=25>&nbsp;</td>
                        <td>
                        <cfif this.Employee.getNonSCFNetworkAccount() EQ 1>
                            #this.Employee.getADUserID()#   
                        <cfelse>
                            None
                        </cfif>                         
                        </td>
                    </tr>
                    
                    <cfif this.Employee.getNonSCFNetworkAccount() EQ 1>
                        <tr>
                            <td>&nbsp;</td>
                            <td>Password (required to change @ first login):</td>
                            <td>&nbsp;</td>
                            <td>Password10! (case sensitive)</td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>Home Directory:</td>
                            <td>&nbsp;</td>
                            <td>#this.Container.getHomeDir()#\#this.Employee.getADUserID()#</td>
                        </tr>
                    </cfif>
            
                    <tr>
                        <td>&nbsp;</td>
                        <td>Start Date:</td>
                        <td>&nbsp;</td>
                        <td>#dateformat(this.Employee.getActStartDate(),'mm/dd/yyyy')#</td>
                    </tr>

                    <tr>
                        <td>&nbsp;</td>
                        <td>Expiration Date:</td>
                        <td>&nbsp;</td>
                        <td>#dateformat(this.Employee.getExpirationDate(),'mm/dd/yyyy')#</td>
                    </tr>
              
                    <cfif this.Employee.getDeskPhone() NEQ "">
                        <tr>
                            <td>&nbsp;</td>
                            <td>Desk Phone:<BR />(as it will appear in the Address Book)</td>
                            <td>&nbsp;</td>
                            <td>#this.Employee.getDeskPhone()#</td>
                        </tr>
                    </cfif>
                </table>                        
            </cfmail>
            
            <cfscript>
                return retObj;
            </cfscript>   
        <cfcatch type="any">
            <cfscript>
                powershell = CreateObject("webservice", "http://scfcas/PowerShellService/?WSDL");
                ps = powershell.Invoke(
                    'add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
                     remove-mailbox -Identity ' &  this.Employee.getADUserID() & ' -Confirm: $false'
                );
                this.Employee.setADUserID("");
                EntitySave(this.Employee);
                retObj = { Message = "<strong>Error</strong> - #CFCatch.Detail#", Result = "Error Creating Rosetta account.  Error detail:<br />" & CFCatch.Detail & CFCatch.Message, Status = 'Fail' };
                creationErrorLog(this.StepID, '#replace(retObj.Result,"\'","'","all")#');
                AlertEmail("Error Creating NonSCFMaster/Rosetta account.", retObj.Result);           
                return retObj;
            </cfscript>
        </cfcatch>
        </cftry>
    </cffunction>
    
    
    <cffunction name="creationComplete" access="public" output="false" returntype="any">
        <cfscript>
            Var retObj = { Status = "Fail", Message = "", Result = "" };
            import models.*;
            StepAction = EntityLoad("StepActions", this.StepID);
            StepAction = StepAction[1];
            StepAction.setActionByID(Session.UserRosettaID);
            StepAction.setActTimeStamp(now());
            StepAction.setNotes('Auto Generated');
            EntitySave(StepAction);
            EntityNew("StepActions");                
            InsertAction = EntityNew("StepActions");
            InsertAction.setEmployeeID(this.Employee.getEmployeeID());
            InsertAction.setStepsID(5);
            InsertAction.setCreationTimeStamp(now());
            EntitySave(InsertAction, true);
            retObj = { Status = "Completed", Message = "<strong>Success</strong>", Result = "" };
            return retObj;
        </cfscript>
    </cffunction>
    
    
    <cffunction name="getLdapUser" access="private" output="false" returntype="any">
        <cfargument name="ADUserAccount" type="string" default="nouser" />
        <cfscript>
            Var SCF_ActiveDirectory = CreateObject("component", 'code_lib.SCF_ActiveDirectory');
            Var ADUp = SCF_ActiveDirectory.isActiveDirectoryUp();
            Var ADObj = {UserDN = "", ADAccount = ""};                    
            if(ADUp){
                ADObj.UserDN = SCF_ActiveDirectory.getUserDNByAccountName(arguments.ADUserAccount);
                ADObj.ADAccount = SCF_ActiveDirectory.getAccountNameByDN(ADObj.UserDN);
            }
            return ADObj;
        </cfscript>  
    </cffunction>
    
    
    <cffunction name="constructUserAccount" access="private" output="false" returntype="any" hint="This function is used to find a free user account for an employee to use.">
        <cfargument name="FirstName" type="string" default="nouser" />
        <cfargument name="LastName" type="string" default="nouser" />
        <cfscript>
            Var UserAccount = '';
            Var NewUserAccount = {Name = "", UserAccount = ""};
            Var counter = 1;
            while(NewUserAccount.UserAccount == ''){
                UserAccount = trim(usePowerShell("get-mailbox #Left(arguments.FirstName, counter)##arguments.LastName# | out-string -width 10000"));
                if( UserAccount == "" ){                    
                    NewUserAccount.UserAccount = '#Left(arguments.FirstName, counter)##arguments.LastName#';
                    NewUserAccount.Name = '#arguments.LastName#, #arguments.FirstName#' & ( counter GT 1 ? " (#counter#)" : "" );
                }
                counter++;
            }
            return NewUserAccount;
        </cfscript>  
    </cffunction>
    
    
    <cffunction name="CreateEmployee" returntype="any" access="private" output="false">
    	<cfscript>
            Var retVal = {};
            Var retVal.SQL = "scf_SCFVM18_CreationStep1_CreateEmployee - #this.Employee.getDOB()#,
            #this.Employee.getActStartDate()#,
            #this.Employee.getFirstName()#,
            #this.Employee.getLastName()#,
            #this.Employee.getPreferredName()#,
            #this.Employee.getMiddleName()#,
            #this.Employee.getSSN()#,
            #this.Employee.getMaritalStatusID()#,
            #this.Employee.getEthnicID()#,
            #this.Employee.getGenderID()#,
            #this.Employee.getPositionID()#,
            #this.PP_REASON_NEW_HIRE#,
            #this.Employee.getSupervisorID()#,
            #this.PRIMARY_POS#,
            #this.PROMOTION#,
            #this.Employee.getExempt()#,
            #this.Employee.getSalaryHourlyID()#,
            #this.Employee.getSeasonal()#,
            #this.Employee.getHoursPerWeek()#,
            #VAL(this.Employee.getWorkersCompID())#,
            #this.COMP_LOCATION_FACTOR#,
            #this.ACTIVE#,
            #this.Employee.getFullTime()#,
            #this.I9_PENDING#,
            #this.ORG_SCF#,
            #this.Employee.getEmployeeCodeID()#,
            #this.Employee.getI9()#,
            #this.ES_REASON_NEW_HIRE#,
            #this.PS_REASON_NEW_HIRE#,
            #this.Employee.getCompTypeID()#,
            #this.Employee.getFrequencyID()#,
            #this.Employee.getPayRate()#,
            #this.AF.AnnualizingFactor#,
            #this.AnnualSalary#,
            #this.BASEPAY#,
            #this.DOLLARS#,
            #this.Employee.getADUserID()#";
            KronosQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.Kronos");
            this.SupervisorHRIDNo = KronosQueries.funcGetCurrentEmployees(Val(this.Employee.getSupervisorID()) );
            this.SupervisorHRIDNo = this.SupervisorHRIDNo.PersonIDNo;                              
        </cfscript>           
        
        <cfstoredproc datasource="#Session.DataSource#" procedure="scf_SCFVM18_CreationStep1_CreateEmployee">  
            <cfprocparam cfsqltype="cf_sql_date" value="#this.Employee.getDOB()#"><!--- @pdteDOB --->
            <cfprocparam cfsqltype="cf_sql_date" value="#this.Employee.getActStartDate()#"><!--- @pdteDOH --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getFirstName()#"><!--- @pstrFirst --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getLastName()#"><!--- @pstrLast --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getPreferredName()#"><!--- @pstrPreferred --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getMiddleName()#"><!--- @pstrMI --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getSSN()#"><!--- @pstrSSN --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getMaritalStatusID())#"><!--- @pintMaritalStatusID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getEthnicID())#"><!--- @pintEthnicID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getGenderID())#"><!--- @pintGenderID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getPositionID())#"><!--- @pintPosID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.PP_REASON_NEW_HIRE)#"><!--- @pintPosReasonID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#this.SupervisorHRIDNo#"><!--- @pintSupervisorID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.PRIMARY_POS)#"><!--- @pintPrimaryPos --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.PROMOTION)#"><!--- @pintPomotion --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getExempt())#"><!--- @pintExempt --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getSalaryHourlyID())#"><!--- @pintSalaryHourlyID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getSeasonal())#"><!--- @pintSeasonal --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getHoursPerWeek())#"><!--- @pintHrsPerWk --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#VAL(this.Employee.getWorkersCompID())#"><!--- @pintWkrsCompID --->
            <cfprocparam cfsqltype='cf_sql_float' value="#this.COMP_LOCATION_FACTOR#"><!--- @pfltCompLocationFactor --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.ACTIVE)#"><!--- @pintEmployeeStatusIDNo --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getFullTime())#"><!--- @pintFullTime --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.I9_PENDING)#"><!--- @pintI9PendingID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.ORG_SCF)#"><!--- @pintOrgCodeID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getEmployeeCodeID())#"><!--- @pintEmploymentCodeID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getI9())#"><!--- @pintI9OnFileID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.ES_REASON_NEW_HIRE)#"><!--- @pintEmploymentStatusReasonID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.PS_REASON_NEW_HIRE)#"><!--- @pintPayReasonID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getCompTypeID())#"><!--- @pintCompTypeID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getFrequencyID())#"><!--- @pintFrequencyID --->
            <cfprocparam cfsqltype="cf_sql_float" value="#this.Employee.getPayRate()#"><!--- @pfltPayRate --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.AF.AnnualizingFactor)#"><!--- @pintAnnualizingFactor --->
            <cfprocparam cfsqltype="cf_sql_float" value="#this.AnnualSalary#"><!--- @pfltAnnualSalary --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.BASEPAY)#"><!--- @pintBasePay --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.DOLLARS)#"><!--- @pintCurrencyID --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getADUserID()#"><!--- @pstrNewUserID --->
            <cfprocresult name="NewID" resultset="1">
            <cfprocresult name="ErrorCheck" resultset="2">
        </cfstoredproc>
        
        <cfscript>
            retVal.NewID = NewID.COMPUTED_COLUMN_1;
            retVal.ErrorCheck = ErrorCheck.Error;
            this.Employee.setHRPersonIDNo(NewID.COMPUTED_COLUMN_1);
            EntitySave(this.Employee);
            this.ReHirePersonIDNo = NewID.COMPUTED_COLUMN_1;
            this.NewHRPersonIDNo = NewID.COMPUTED_COLUMN_1;
            this.trace = " #retVal.SQL# ";
            return retVal;
        </cfscript>        
    </cffunction>
    
    
    <cffunction name="CreateEmployeeRehire" returntype="any" access="private" output="false">
    	<cfscript>
            Var retVal = {};
            Var retVal.SQL = "#this.CheckRehire.PersonIDNo#
                #this.Employee.getPositionID()#
                #this.PP_REHIRE# 
                #this.Employee.getActStartDate()# 
                #this.HRSupervisorID# 
                #this.PRIMARY_POS# 
                #this.PROMOTION# 
                #this.Exempt# 
                #this.Employee.getSalaryHourlyID()# 
                #this.Seasonal# 
                #this.Employee.getHoursPerWeek()# 
                #this.Employee.getWorkersCompID()#
                #this.COMP_LOCATION_FACTOR# 
                #this.PS_REHIRE# 
                #this.Employee.getCompTypeID()# 
                #this.Employee.getFrequencyID()# 
                #this.Employee.getPayRate()# 
                #this.AF.AnnualizingFactor#
                #this.AnnualSalary# 
                #this.BASEPAY# 
                #this.DOLLARS# 
                #this.ACTIVE# 
                #this.Employee.getEmployeeCodeID()# 
                #this.FullTime# 
                #this.Employee.getI9()# 
                #this.ORG_SCF#
                #this.ES_REHIRE# 
                #this.REHIRE# 
                #this.Employee.getDOB()# 
                #this.Employee.getFirstName()# 
                #this.Employee.getLastName()# 
                #this.Employee.getMaritalStatusID()#
                #this.Employee.getMiddleName()# 
                #this.Employee.getPreferredName()# 
                #this.Employee.getEthnicID()# 
                #this.Employee.getGenderID()# 
                #this.Employee.getSSN()# 
                #this.NewUserAccount#";
                KronosQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.Kronos");
            this.SupervisorHRIDNo = KronosQueries.funcGetCurrentEmployees(Val(this.Employee.getSupervisorID()) );
            this.SupervisorHRIDNo = this.SupervisorHRIDNo.PersonIDNo;
        </cfscript>           
        
        <cfstoredproc datasource="#Session.DataSource#" procedure="scf_SCFVM18_RehireStep1">  
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.CheckRehire.PersonIDNo)#"><!---@pintPersonIDNo --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getPositionID())#"><!---@pintPosID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.PP_REHIRE)#"><!---@pintPosStatusID --->
            <cfprocparam cfsqltype="cf_sql_date" value="#this.Employee.getActStartDate()#"><!---@pdteHire --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.HRSupervisorID)#"><!---@pintHRSupID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.PRIMARY_POS)#"><!---@pintPrimaryPos --Always (-1) --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.PROMOTION)#"><!---@pintPromotion --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Exempt)#"><!---@pintExempt --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getSalaryHourlyID())#"><!---@pintSalaryHourlyID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Seasonal)#"><!---@pintSeasonal      --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getHoursPerWeek())#"><!---@pintHrsPerWk --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#VAL(this.Employee.getWorkersCompID())#"><!---@pintWrksCompID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.COMP_LOCATION_FACTOR)#"><!---@pintCompLocFactor --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.PS_REHIRE)#"><!---@pintPayStatusID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getCompTypeID())#"><!---@pintCompTypeID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getFrequencyID())#"><!---@pintFreqID --->
            <cfprocparam cfsqltype="cf_sql_float" value="#this.Employee.getPayRate()#"><!---@pfltPayRate --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.AF.AnnualizingFactor)#"><!---@pintAnnualizingFactor --->
            <cfprocparam cfsqltype="cf_sql_float" value="#this.AnnualSalary#"><!---@pfltAnnualSalary --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.BASEPAY)#"><!---@pintBasePay --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.DOLLARS)#"><!---@pintDollars --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.ACTIVE)#"><!---@pintActive --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getEmployeeCodeID())#"><!---@pintEmploymentCodeID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.FullTime)#"><!---@pintFullTime --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getI9())#"><!---@pintI9OnFileID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.ORG_SCF)#"><!---@pintOrgID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.ES_REHIRE)#"><!---@pintESID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.REHIRE)#"><!---@pintAction --->
            <cfprocparam cfsqltype="cf_sql_date" value="#this.Employee.getDOB()#"><!---@pdteDOB --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getFirstName()#"><!---@pstrFirst --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getLastName()#"><!---@pstrLast --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getMaritalStatusID())#"><!---@pintMaritalStatusID --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getMiddleName()#"><!---@pstrMiddle --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getPreferredName()#"><!---@pstrPreferred --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getEthnicID())#"><!---@pintEthnicCodeID --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#VAL(this.Employee.getGenderID())#"><!---@pintGenderID --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getSSN()#"><!---@pstrSSN --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.NewUserAccount#"><!---@pstrNewUserID --->
            <cfprocresult name="NewID" resultset="1">
            <cfprocresult name="ErrorCheck" resultset="2">
        </cfstoredproc>
        
        <cfscript>
            retVal.NewID = NewID.COMPUTED_COLUMN_1;
            retVal.ErrorCheck = ErrorCheck.Error;
            this.Employee.setHRPersonIDNo(NewID.COMPUTED_COLUMN_1);
            this.ReHirePersonIDNo = NewID.COMPUTED_COLUMN_1;
            this.NewHRPersonIDNo = NewID.COMPUTED_COLUMN_1;
            EntitySave(this.Employee);
            this.trace = "scf_SCFVM18_RehireStep1 - #retVal.SQL#";
            return retVal;
        </cfscript>
    </cffunction>
    
    
    <cffunction name="UpdatePrimaryPhones" returntype="any" access="private" output="false">
    	<cfquery name ="qryUpdatePrimaryPhones" datasource="#Session.DataSource#">
            scf_SCFVM18_PrimePhones #this.Employee.getHRPersonIDNo()#, '#dateformat(dateadd("d", -1, this.Employee.getActStartDate()),"mm/dd/yyyy")#'
        </cfquery>
        <cfscript>
            this.trace = " scf_SCFVM18_PrimePhones - #this.Employee.getHRPersonIDNo()#, '#dateformat(dateadd("d", -1, this.Employee.getActStartDate()),"mm/dd/yyyy")#'";
        </cfscript>        
    </cffunction>
    

    <cffunction name="CreateEmployeeEmergencyContact" returntype="any" access="private" output="false">
        <cfscript>
            Var retVal = {Result = "", Error = "", SQL = ""};
            Var ContactOrder = 1;
        </cfscript>
              
        <cfloop from="1" to="#ArrayLen(this.EmpECInfo)#" index="i"> 
            <cfset retVal.SQL &= " scf_SCFVM18_CreationStep3_EmergencyContact -
                #this.NewHRPersonIDNo#,
                #this.Employee.getActStartDate()#,
                #this.EmpECInfo[i].getFirstName()#,
                #this.EmpECInfo[i].getLastName()#,
                #this.EmpECInfo[i].getRelationID()#,
                #ContactOrder#,
                #this.EMP_ADDRESS_TYPE#,
                #this.EmpECInfo[i].getAddress1()#,
                #this.EmpECInfo[i].getAddress2()#,
                #this.EmpECInfo[i].getCity()#,
                #this.EmpECInfo[i].getState()#,
                #this.EmpECInfo[i].getZip()#,
                #this.USA#,
                #Replace( this.EmpECInfo[i].getHomePhone(), "-", "", "All")#,
                #Replace( this.EmpECInfo[i].getCellPhone(), "-", "", "All")#,
                #Replace( this.EmpECInfo[i].getWorkPhone(), "-", "", "All")#,
                #this.EmpECInfo[i].getWorkPhoneExtention()#,
                #this.EmpECInfo[i].getPhonePrimaryID()#,
            " />
            <cfstoredproc datasource="#Session.DataSource#" procedure="scf_SCFVM18_CreationStep3_EmergencyContact">  
                <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.NewHRPersonIDNo)#" />, <!--- @pintPersonIDNo --->
                <cfprocparam cfsqltype="cf_sql_date" value="#this.Employee.getActStartDate()#" />, <!--- @pdteDOH --->
                <cfprocparam cfsqltype="cf_sql_varchar" value="#this.EmpECInfo[i].getFirstName()#" />, <!--- @pstrFirst --->
                <cfprocparam cfsqltype="cf_sql_varchar" value="#this.EmpECInfo[i].getLastName()#" />, <!--- @pstrLast --->
                <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.EmpECInfo[i].getRelationID())#" />, <!--- @pintRelationID --->
                <cfprocparam cfsqltype="cf_sql_integer" value="#Val(ContactOrder)#" />,<!--- @pintContactOrder --->
                <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.EMP_ADDRESS_TYPE)#" />, <!---@pintAddressTypeID --->
                <cfprocparam cfsqltype="cf_sql_varchar" value="#this.EmpECInfo[i].getAddress1()#" />, <!--- @pstrAddress1 --->
                <cfprocparam cfsqltype="cf_sql_varchar" value="#this.EmpECInfo[i].getAddress2()#" />, <!---@pstrAddress2 --->
                <cfprocparam cfsqltype="cf_sql_varchar" value="#this.EmpECInfo[i].getCity()#" />, <!--- @pstrCity --->
                <cfprocparam cfsqltype="cf_sql_varchar" value="#this.EmpECInfo[i].getState()#" />, <!--- @pintStateID --->
                <cfprocparam cfsqltype="cf_sql_varchar" value="#this.EmpECInfo[i].getZip()#" />, <!--- @pstrZIP --->
                <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.USA)#" />, <!--- @pintUSAID --->
                <cfprocparam cfsqltype="cf_sql_varchar" value='#Replace( this.EmpECInfo[i].getHomePhone(), "-", "", "All")#' />, <!--- @pstrHomePhone --->
                <cfprocparam cfsqltype="cf_sql_varchar" value="#Replace( this.EmpECInfo[i].getCellPhone(), "-", "", "All")#" />,<!--- @pstrCellPhone --->
                <cfprocparam cfsqltype="cf_sql_varchar" value="#Replace( this.EmpECInfo[i].getWorkPhone(), "-", "", "All")#" />,<!--- @pstrWorkPhone --->
                <cfprocparam cfsqltype="cf_sql_varchar" value="#this.EmpECInfo[i].getWorkPhoneExtention()#" />,<!--- @pstrWorkExt --->
                <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.EmpECInfo[i].getPhonePrimaryID())#" /> <!---@pintPrimaryPhoneID --->
                <cfprocresult name="ErrorCheck" resultset="1">
            </cfstoredproc>
            
            <cfscript>
                if(ErrorCheck.Error NEQ 0){
                    retVal.HRResult &= "Error creating Emergency Contact record for #First# #Last#.  Please check the record in the Kronos HR tools and fix manually if necessary.<BR/>";
                    retVal.Result = ErrorCheck.Error;                    
                }
                ContactOrder += 1;
            </cfscript>
        </cfloop>
        <cfset this.trace = " scf_SCFVM18_CreationStep3_EmergencyContact #retVal.SQL#" />
        <cfreturn retVal />

    </cffunction>
        
    
    <cffunction name="CreateEmployeeAddressesPhones" returntype="any" access="private" output="false">
    	<cfscript>
            Var retVal = {SQL = "", ErrorCheck = 0};
            Var retVal.SQL = "scf_SCFVM18_CreationStep2_AddressesPhones -  (#this.NewHRPersonIDNo#,
                #DateFormat(this.Employee.getActStartDate(), 'm-d-yyyy')#,
                #this.EMP_ADDRESS_TYPE#,
                #this.Employee.getAddress1()#,
                #this.Employee.getAddress2()#,
                #this.Employee.getCity()#,
                #this.Employee.getState()#,
                #this.Employee.getZip()#,
                #this.USA#,
                #Replace( this.Employee.getHomePhone(), "-", "", "All")#,
                #Replace( this.Employee.getCellPhone(), "-", "", "All")#,
                #Replace( this.Employee.getWorkPhone(), "-", "", "All")#,
                #this.Employee.getWorkPhoneExtention()#,
                #this.Employee.getPhonePrimaryID()#)
            ";
            this.trace = " #retVal.SQL#";                                
        </cfscript>
        
        <cfquery name="qryCreationStep2_AddressesPhones" datasource="#Session.DataSource#">
            scf_SCFVM18_CreationStep2_AddressesPhones #Val(this.NewHRPersonIDNo)#, 
                N'#DateFormat(this.Employee.getActStartDate(), "m-d-yyyy")#', 
                #Val(this.EMP_ADDRESS_TYPE)#, 
                N'#this.Employee.getAddress1()#', 
                N'#this.Employee.getAddress2()#',
                N'#this.Employee.getCity()#', 
                #Val(this.Employee.getState())#, 
                N'#this.Employee.getZip()#', 
                #Val(this.USA)#, 
                N'#this.Employee.getHomePhone()#', 
                N'#this.Employee.getCellPhone()#', 
                N'#this.Employee.getWorkPhone()#', 
                N'#this.Employee.getWorkPhoneExtention()#', 
                #Val(this.Employee.getPhonePrimaryID())#
        </cfquery>
        
        <!---<cfstoredproc datasource="#Session.DataSource#" procedure="scf_SCFVM18_CreationStep2_AddressesPhones">  
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.NewHRPersonIDNo)#" /> <!--- @pintPersonIDNo --->
            <cfprocparam cfsqltype="cf_sql_date" value="#DateFormat(this.Employee.getActStartDate(), 'm-d-yyyy')#" /> <!--- @pdteDOH --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.EMP_ADDRESS_TYPE)#" /> <!--- @pintAddressTypeID --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getAddress1()#" /> <!--- @pstrAddress1 --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getAddress2()#" /> <!--- @pstrAddress2 --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getCity()#" /> <!--- @pstrCity --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getState())#" /> <!--- @pintStateID --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getZip()#" /> <!--- @pstrZIP --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.USA)#" /> <!--- @pintUSAID --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#Replace( this.Employee.getHomePhone(), "-", "", "All")#" /> <!--- @pstrHomePhone --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#Replace( this.Employee.getCellPhone(), "-", "", "All")#" /> <!--- @pstrCellPhone --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#Replace( this.Employee.getWorkPhone(), "-", "", "All")#" /> <!--- @pstrWorkPhone --->
            <cfprocparam cfsqltype="cf_sql_varchar" value="#this.Employee.getWorkPhoneExtention()#" /> <!--- @pstrWorkExt --->
            <cfprocparam cfsqltype="cf_sql_integer" value="#Val(this.Employee.getPhonePrimaryID())#" /><!--- @pintPrimaryPhoneID --->
            <cfprocresult name="ErrorCheck" resultset="1">
        </cfstoredproc>--->

        <cfscript>
            retVal.ErrorCheck = qryCreationStep2_AddressesPhones.Error;
            return retVal;
        </cfscript>

    </cffunction>
    
    
    <cffunction name="CreateRosetta" returntype="any" access="private" output="false">
        <cfquery name="qryCreateRosettaRecord" datasource="#Session.DataSourceRosetta#">         
            Insert into RosettaStone (
                UserAccount, AD_GUID, HRProd_PersonIDNo, EPAR_ID, [Disabled]
            )
            Values (
                <cfif this.Employee.getADUserID() NEQ ''><cfqueryparam cfsqltype="cf_sql_varchar" value="#this.Employee.getADUserID()#" /><cfelse>NULL</cfif>, 
                <cfif this.Employee.getADGUID() NEQ ''><cfqueryparam cfsqltype="cf_sql_varchar" value="#this.Employee.getADGUID()#" /><cfelse>NULL</cfif>, 
                <cfif this.Employee.getHRPersonIDNo() NEQ -1 OR this.Employee.getHRPersonIDNo() NEQ ''><cfqueryparam cfsqltype="cf_sql_integer" value="#this.Employee.getHRPersonIDNo()#" /><cfelse>NULL</cfif>, 
                <cfif this.Employee.getEmployeeID() NEQ 0 OR this.Employee.getEmployeeID() NEQ ''><cfqueryparam cfsqltype="cf_sql_integer" value="#this.Employee.getEmployeeID()#" /><cfelse>NULL</cfif>, 
                1
            )            
            SELECT @@Identity AS NewRosettaID
        </cfquery>        
        <cfreturn qryCreateRosettaRecord />
    </cffunction>

    
    <cffunction name="creationErrorLog" access="private" output="false" returntype="void">
        <cfargument name="StepID" type="string" default="-1111" />
        <cfargument name="Message" type="string" default="" />
        <cfquery name="qryInsertErrorLog" datasource="#Session.DataSource#">
            scf_InsertErrorLog #arguments.StepID#, #Session.UserRosettaID#, N'#arguments.Message#'
        </cfquery>
    </cffunction>
    
    
    <cffunction name="AlertEmail" access="public" output="false" returntype="void">
        <cfargument name="EmailSubject" type="string" required="false" default="EPAR Error" />
        <cfargument name="EmailBody" type="string" required="false" default="" />
        <cfargument name="From" type="string" required="false" default="EPAR_Creation@scf.cc" />
        <cfargument name="To" type="string" required="false" default="#Session.SERVICEDESK_EMAIL#" />
        
        <cfmail to=#ARGUMENTS.To# From="#ARGUMENTS.From#" subject="#ARGUMENTS.EmailSubject#" type="html">            
            #ARGUMENTS.EmailBody#            
        </cfmail>                
    </cffunction>
    
    
    <cffunction name="usePowerShell" access="public" output="false" returntype="any">
        <cfargument name="PSCommands" type="string" default="get-mailbox XXXTestXXX | out-string -width 10000" />
        <cfscript>
            powershell = CreateObject("webservice", "http://scfcas/PowerShellService/?WSDL", {username = 'SCF\Userlist', password = 'DefinedMan'});
            result = powershell.Invoke(
                'add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
                #arguments.PSCommands#'
            );
            return result;
        </cfscript>  
    </cffunction>

</cfcomponent>